package com.fay.designPattern.pattern.create.singleton.u42;

/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/4/9 10:03
 * @Version 1.0
 */
public class Singleton0 {
    private static Singleton0 instance = null;
    private final int paramA;
    private final int paramB;

    public Singleton0(int paramA, int paramB) {
        this.paramA = paramA;
        this.paramB = paramB;
    }

    public static Singleton0 getInstance() {
        if (instance == null) {
            throw new RuntimeException("Run init() first.");
        }
        return instance;
    }

    public synchronized static void init(int paramA, int paramB) {
        if (instance != null) {
            throw new RuntimeException("Singleton has been created!");
        }
        instance = new Singleton0(paramA, paramB);
    }

    public static void main(String[] args) {
        Singleton0.init(10, 50);
        System.out.println(Singleton0.getInstance());
        Singleton0.init(20, 50);
        System.out.println(Singleton0.getInstance());
    }
}
